package com;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;

public class Server extends UntypedActor{
	static final String AkkaSystemName = "xw";
	LoggingAdapter log = Logging.getLogger(getContext().system(), this);
	private ActorRef actor = null;
	
	@Override
    public void preStart() {
		ActorSystem system = ActorSystem.create("MySystem");
        // 创建一个名为child的子actor
		actor = system.actorOf(Props.apply(Client.class), "clientTemp");
        
    }


	@Override
	public void onReceive(Object message) throws Exception {
		System.out.println("nimab    *************************** woshi Server");
		System.out.println("getSender()*********************"+getSender());
		//log.info("server收到消息---${message}----self:${getSelf()}----,sender:${getSender()}"+getSender()+":message*****:"+message);
		/*ActorSystem system = ActorSystem.create("mySystem");
		system.actorOf(Props.apply(Client.class), "clientTemp");
		ActorRef service = system.actorFor("akka://mySystem/user/clientTemp");
        service.tell("sss", getSelf());*/
		actor.tell("bb jiao client ******",getSelf());
		unhandled(message);
        
	}
	
	public static void main(String[] args) {
		/*System.out.println("nimab    *************************** begin Client");
		akka.actor.ActorSystem.create(Server.AkkaSystemName, ConfigFactory.load().getConfig("client")).actorFor("akka://xw@127.0.0.1:25452/user/server").tell("hello,I'm client");
		System.out.println("nimab    *************************** over Client");*/
		
		 ActorSystem system = ActorSystem.create("mySystem");
	        // 创建一个名为service的顶级actor
        system.actorOf(Props.apply(Client.class), "clientTemp");
        // 使用绝对路径获取service
        ActorRef service = system.actorFor("akka://mySystem/user/clientTemp");
        service.tell("sss", service);
	}

}
